using Microsoft.Practices.Unity;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using UniAspect.UnityCommon;

namespace UniAspect.UnitTests
{
    [TestFixture]
    public class ChildContainersBehavior
    {
        private class Implementation1 : ISomeStubInterface
        {
            
        }

        private class Implementation2 : ISomeStubInterface
        {
            
        }

        private class BaseStub : IBaseInterface { }

        private interface ISomeStubInterface
        {
            //string Name { get; }
        }

        private interface IBaseInterface { }

        class Dependant
        {
            [Dependency]
            public ISomeStubInterface Changing { get; set; }
            [Dependency]
            public IBaseInterface Base { get; set; }
        }

        [Test]
        public void DifferentImplementation()
        {
            var container = new UnityContainer();
            //container.AddExtension(new ResolutionLoggingExtension(new ConsoleResolutionLogger()));
            var child = container.CreateChildContainer();

            container.RegisterSingleton<IBaseInterface, BaseStub>();
            container.RegisterSingleton<ISomeStubInterface, Implementation1>();

            child.RegisterSingleton<ISomeStubInterface, Implementation2>();
            child.RegisterSingleton<Dependant>();

            var instance = container.Resolve<Dependant>();
            var childInstance = child.Resolve<Dependant>();

            Assert.That(instance.Changing, Is.InstanceOfType(typeof(Implementation1)));
            Assert.That(childInstance.Changing, Is.InstanceOfType(typeof(Implementation2)));
        }
    }
}